package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Courseorder;
import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.query.CourseQuery;
import cn.wolfcode.crm.service.ICourseService;
import cn.wolfcode.crm.service.ICustomerService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private ICourseService courseService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")CourseQuery qo){
        PageInfo pageInfo = courseService.listAll(qo);//销售课程数据
        //查询所有潜在客户
        List<Customer> customers = customerService.selectByStatus(Customer.STATUS_COMMON);
        //查询所有课程
        List<SystemDictionaryItem> subject = systemDictionaryItemService.selectByDicSn("subject");
        model.addAttribute("result",pageInfo);
        model.addAttribute("course",subject);
        model.addAttribute("customers",customers);

        return "/course/list";
    }


    @RequestMapping("/saveOrUpdate")
    public JsonResult list(Model model, String id, String customerId, String courseId, String money){
        courseService.saveOrUpdate(id,customerId,courseId,money);
        return new JsonResult();
    }
}
